package com.xh.demo.controller;

import com.xh.demo.mq.amqp.dlx.DelayMsgProducer;
import com.xh.demo.mq.amqp.ttl.TtlMsgProducer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wen
 * @apiNote TestAmqpController
 * @since 2021-08-05
 */
@Api(tags = {"AMQP实现延时消息"})
@RestController
@RequestMapping("/amqp")
public class TestAmqpController {

    @Autowired
    private TtlMsgProducer ttlMsgProducer;
    @Autowired
    private DelayMsgProducer delayMsgProducer;

    @ApiOperation(value = "ttl实现延时消息")
    @GetMapping("ttl/send/{msg}/{time}")
    public String sendTtl(@ApiParam(name = "msg", value = "消息内容", required = true) @PathVariable("msg") String msg,
                          @ApiParam(name = "time", value = "延时消费时间（ms）", required = true) @PathVariable("time") long time) {
        ttlMsgProducer.sendDelayedMsg(msg, time);
        return "SUCCESS";
    }

    @ApiOperation(value = "dlx实现延时消息")
    @GetMapping("dlx/send/{msg}/{time}")
    public String sendDlx(@ApiParam(name = "msg", value = "消息内容", required = true) @PathVariable("msg") String msg,
                          @ApiParam(name = "time", value = "延时消费时间（ms）", required = true) @PathVariable("time") long time) {
        delayMsgProducer.sendDelayedMsg(msg, time);
        return "SUCCESS";
    }

}
